package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.view.View;


import androidx.databinding.library.baseAdapters.BR;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemSearchRecyclerFlowBinding;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class SearchFlowLayoutAdapter extends BaseRecycleAdapter<String> {

    private boolean isDelete;

    public SearchFlowLayoutAdapter(Context context, List<String> datas) {
        super(context, R.layout.item_search_recycler_flow, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final String entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemSearchRecyclerFlowBinding binding = ((ItemSearchRecyclerFlowBinding) holder.getmBinding());
        binding.rlDelete.setVisibility(isDelete ? View.VISIBLE : View.GONE);
        binding.rlDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isDelete()) {
                    getDatas().remove(holder.getAdapterPosition());
                    notifyDataSetChanged();
                }
            }
        });
    }

    public boolean isDelete() {
        return isDelete;
    }

    public void setDelete(boolean delete) {
        isDelete = delete;
        notifyDataSetChanged();
    }
}
